<?php
    $this->Js->JqueryEngine->jQueryObject = '$j';
    echo $this->Html->scriptBlock('var $j = jQuery.noConflict();', array('inline' => false));
    $this->Paginator->options(array('update' => '#divDocumentos', 'evalScripts' => true, 
        'before' => '$j.fn.show_div_loader()', 
        'complete' => '$j.fn.hide_div_loader()'));
    
    echo "<br/><span class='info-paginador'>{$this->Paginator->counter('Registros: <b>{:start}</b> al <b>{:end}</b> - Total: <b>{:count}</b>')}</span>";
?>
<script type="text/javascript">
    $j('button.detalle').button({icons: {primary: 'ui-icon-search'}, text: false}).click(function(){
        var idTrPadre = $j(this).parents('tr').attr('id');
        $j.ajax({
            url: 'Facturacions/detalle',
            type: 'POST',
            data: { id: idTrPadre },
            success: function(data){
                dialogoDetalle.html(data).dialog('open');
            }
        });
        return false;
    });
    
    $j("button.btn_dialogo, td.info").tooltip({
        show: true,
        hide: true
    });
    
    $j('button.facturada').button({icons: {primary: 'ui-icon-check'}, text: false}).click(function(){
        return false;
    });
    
    $j('button.anulada').button({icons: {primary: 'ui-icon-cancel'}, text: false}).click(function(){
        return false;
    });
    
    $j('button.devuelta').button({icons: {primary: 'ui-icon-refresh'}, text: false}).click(function(){
        return false;
    });
</script>
<table class="tabla-dialogo">
    <tr>
        <th width="40">Caja</th>
        <th width="200"><?php echo $this->Paginator->sort('Facturacion.numero', 'Numero', array('direction' => 'desc'));?></th>
        <th width="100">C&eacute;dula/Rif</th>
        <th>Nombre Cliente</th>
        <th width="120"><?php echo $this->Paginator->sort('Facturacion.Fecha', 'Fecha', array('direction' => 'desc'));?></th>
        <th width="100">Monto</th>
        <th>Estado</th>
        <th>Acci&oacute;n</th>
    </tr>
    <?php if(empty($data)) { ?>
        <tr>
            <td colspan="8" class="centro">No se encontraron registros</td>
        </tr>
    <?php
        } else {
            foreach($data as $valor){
                switch ($valor['Facturacion']['estatus']){
                    case 1:
                        $icono = 'facturada';
                    break;
                    case 2:
                        $icono = 'anulada';
                    break;
                    case 3:
                        $icono = 'devuelta';
                    break;
                }
    ?>
        <tr id="<?php echo $this->Formulario->id($valor['Facturacion']['id']); ?>">
            <td class="centro"><?php echo str_replace('CAJA ', '', $valor['Punto']['nombre']); ?></td>
            <td class="centro info" title="<?php echo $valor['Facturacion']['numero']; ?>"><?php echo $this->Interfaz->recortar_documento($valor['Facturacion']['numero']); ?></td>
            <td class="centro"><?php echo $this->Formulario->formatocedula($valor['Cliente']['documento']); ?></td>
            <td class="info" title="<?php echo $valor['Cliente']['nombre']; ?>"><div class="recortar"><?php echo $valor['Cliente']['nombre']; ?></div></td>
            <td class="centro"><?php echo $fecha = $this->Interfaz->fechatime($valor['Facturacion']['fecha'], 'F'); ?></td>
            <td class="centro"><?php echo $this->Interfaz->miles($valor['Facturacion']['monto']); ?></td>
            <td class="centro"><button class="btn_dialogo <?php echo $icono; ?>"><?php echo strtoupper($icono); ?></button></td>
            <td class="centro" style="height: 34px">
            <?php if($valor['Facturacion']['tipo'] == 'N'){ ?>               
                <button class="btn_dialogo detalle">ACCIONES</button>
                <?php } else { ?>
                FLETE
                <?php } ?>
            </td>
        </tr>
    <?php
            }
        }
    ?>
</table>
<?php
    echo $this->Paginator->first('<< ', array('class' => 'normal')) . ' ';
    echo $this->Paginator->prev('< ', array('class' => 'normal')) . ' ';
    echo $this->Paginator->numbers(array('modulus' => '2', 'class' => 'normal', 'currentClass' => 'actual')) . ' ';
    echo $this->Paginator->next('>', array('class' => 'normal')) . ' ';
    echo $this->Paginator->last('>>', array('class' => 'normal'));
    echo $this->Js->writeBuffer();
?>